package com.fhz.module_main

import android.os.Bundle
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.fhz.lib_base.ARouterPath
import com.fhz.loginmvvm.callback.ApiSuccessResponse
import com.fhz.module_main.adapter.IndexViewPageAdapter
import com.fhz.module_main.databinding.ActivityMainBinding
import com.fhz.module_main.viewmodel.IndexViewModel
import com.gyf.immersionbar.ImmersionBar
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class MainActivity : AppCompatActivity() {

     val indexViewModel:IndexViewModel by viewModels()

    private lateinit var binding: ActivityMainBinding
    lateinit var mutableListOfFragment:MutableList<Fragment>

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(binding.root)

        //状态栏修改
        ImmersionBar.with(this)
            .fitsSystemWindows(true)
            .statusBarColor(R.color.white)
            .statusBarDarkFont(true)
            .init()

        mutableListOfFragment = mutableListOf()

        initFragment()
        binding.mainVp.adapter = IndexViewPageAdapter(mutableListOfFragment,supportFragmentManager,BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT)

        val nav = binding.mainBottomBar.material()
            .addItem(android.R.drawable.ic_menu_camera, "首页")
//            .addItem(android.R.drawable.ic_menu_compass, "社区")
//            .addItem(android.R.drawable.ic_menu_search, "通知")
            .addItem(android.R.drawable.ic_menu_help, "我的")
            .enableAnimateLayoutChanges()
            .build()

        //可以和vp绑定
        nav.setupWithViewPager(binding.mainVp)
        //底部导航监听
        // 选中时触发
        nav.addSimpleTabItemSelectedListener { index, old ->
//            when(index){
//                0 -> {
//                    ARouter.getInstance().build(ARouterPath.MAIN_INDEX).navigation()
//                }
//                1 -> {
//                    ARouter.getInstance().build(ARouterPath.MINE_INDEX).navigation()
//                }
//                2 -> {
//                    ARouter.getInstance().build(ARouterPath.MINE_INDEX).navigation()
//                }
//                3 -> {
//                    ARouter.getInstance().build(ARouterPath.MINE_INDEX).navigation()
//                }
//            }
        }


//        indexViewModel.login("q1","1").observe(this){
//            val apiSuccessResponse = it as ApiSuccessResponse
//            println(apiSuccessResponse)
//            binding.userRv.adapter = UserAdapter(apiSuccessResponse.body.data)
//            userViewModel.insertUser(apiSuccessResponse.body.data)
//        }

    }

   private fun initFragment(){
        val mainFragment = ARouter.getInstance().build(ARouterPath.MAIN_INDEX).navigation() as Fragment
//        val communityFragment = ARouter.getInstance().build(ARouterPath.COMMUNITY_INDEX).navigation()as Fragment
//        val notificationFragment = ARouter.getInstance().build(ARouterPath.NOTIFICATION_INDEX).navigation()as Fragment
        val mineFragment = ARouter.getInstance().build(ARouterPath.MINE_INDEX).navigation()as Fragment

       mutableListOfFragment.add(mainFragment)
//        mutableListOfFragment.add(communityFragment)
//        mutableListOfFragment.add(notificationFragment)
       mutableListOfFragment.add(mineFragment)
//        binding.mainVp.adapter.setData(mutableListOfFragment)
    }


}

